
import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import Blank from '@/layout/blank-index'

import { genRouterMap } from './gen'

Vue.use(Router)

export const constantRouterMap = [
  {
    path: '/login',
    name: 'Login',
    meta: { title: '登录', noCache: true },
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    name: 'Register',
    meta: { title: '注册', noCache: true },
    component: () => import('@/views/login/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/403',
    component: () => import('@/views/403'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true, noCache: true }
      }
    ]
  }
].concat(genRouterMap)

export const asyncRouterMap = [
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    meta: {
      title: '系统维护',
      icon: 'server'
    },
    children: [
      {
        path: 'system',
        component: () => import('@/views/system/System'),
        name: 'System',
        meta: { title: '系统管理', icon: 'app1', affix: true, noCache: true }
      },
      {
        path: 'menu',
        component: () => import('@/views/system/Menu'),
        name: 'Menu',
        meta: { title: '菜单管理', icon: 'nested', affix: true, noCache: true }
      },
      {
        path: 'interface',
        component: () => import('@/views/system/Interface'),
        name: 'Interface',
        meta: { title: '接口管理', icon: 'form', affix: true, noCache: true }
      },
      {
        path: 'button',
        component: () => import('@/views/system/Button'),
        name: 'Button',
        meta: { title: '按钮管理', icon: 'link', affix: true, noCache: true }
      },
      {
        path: 'contract',
        component: () => import('@/views/system/Contract'),
        name: 'Contract',
        meta: { title: '合同管理', icon: 'copy', affix: true, noCache: true }
      }
    ]
  },
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission',
    meta: {
      title: '权限维护',
      icon: 'table'
    },
    children: [
      {
        path: 'group',
        component: () => import('@/views/permission/Group'),
        name: 'Group',
        meta: { title: '权限组管理', icon: 'group', affix: true, noCache: true }
      },
      {
        path: 'permission',
        component: () => import('@/views/permission/Permission'),
        name: 'Permission',
        meta: { title: '授权管理', icon: 'nested', affix: true, noCache: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user',
    meta: {
      title: '用户维护',
      icon: 'user'
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/user/User'),
        name: 'User',
        meta: { title: '用户管理', icon: 'user', affix: true, noCache: true }
      },
      {
        path: 'relation',
        component: () => import('@/views/user/Relation'),
        name: 'Relation',
        meta: { title: '授权配置', icon: 'nested', affix: true, noCache: true }
      },
      {
        path: 'teacher',
        component: () => import('@/views/user/Teacher'),
        name: 'Teacher',
        meta: { title: '教师管理', icon: 'manager', affix: true, noCache: true }
      },
      {
        path: 'student',
        component: () => import('@/views/user/Student'),
        name: 'Student',
        meta: { title: '学生管理', icon: 'user', affix: true, noCache: true }
      }
    ]
  },
  {
    path: '/changePassword',
    component: Layout,
    redirect: '/common',
    children: [
      {
        path: 'changePassword',
        component: () => import('@/views/ChangePassword'),
        name: 'ChangePassword',
        meta: { title: '修改密码', icon: 'setting', affix: true, noCache: true }
      }
    ]
  },
]

export default new Router({
  // mode: 'history',
  exact: false,
  linkActiveClass: 'active',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
